﻿using Furion.DatabaseAccessor;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore;

namespace BlazorOrdering.Core
{
    /// <summary>
    /// 订单子项，详单
    /// </summary>
    public class OrderStatement : Entity, IEntityTypeBuilder<OrderStatement>
    {
        [Required(ErrorMessage = "请选择用餐日期")]
        [DisplayName("用餐日期")]
        [DisplayFormat(DataFormatString = "{0:yyyy年MM月dd日 dddd}")]
        public DateTime Day { get; set; }

        [Required(ErrorMessage = "请选择用餐类型")]
        [DisplayName("用餐类型")]
        public string Type { get; set; }


        [Required(ErrorMessage = "请填写价格（价格范围1-99）")]
        [Range(1, 99, ErrorMessage = "价格不能大于{2} 不能小于{1}")]
        [DisplayName("单价（元）")]
        public double Price { get; set; }

        [Required(ErrorMessage = "请选择菜名")]
        [DisplayName("菜名")]
        public string Name { get; set; }

        [Required(ErrorMessage = "请填写份数（价格范围1-99）")]
        [Range(1, 99, ErrorMessage = "份数不能大于{2} 不能小于{1}")]
        [DisplayName("份数")]
        public double Number { get; set; }


        [Required(ErrorMessage = "请填写小计")]
        [Range(1, 9999, ErrorMessage = "小计不能大于{2} 不能小于{1}")]
        [DisplayName("小计")]
        public double subtotal { get; set; }

        public void Configure(EntityTypeBuilder<OrderStatement> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            entityBuilder.HasKey(u => u.Id);//将单个属性配置为实体的主键
            entityBuilder.Property(b => b.CreatedTime).HasDefaultValueSql("getdate()");
        }
    }
}
